package com.resource.coursemanage.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.resource.common.utils.R;
import com.resource.coursemanage.entity.TCourseInformationEntity;
import com.resource.coursemanage.entity.TResourceInformationEntity;
import com.resource.coursemanage.mapper.TResourceInformationDao;
import com.resource.coursemanage.service.TResourceInformationService;
//import io.renren.modules.sys.feign.StudyCourseRemote;
import io.renren.modules.sys.feign.StudyCourseRemote;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Set;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.resource.common.utils.PageUtils;
import com.resource.common.utils.Query;
import org.springframework.web.client.RestTemplate;


@Service
public class TResourceInformationServiceImpl extends ServiceImpl<TResourceInformationDao, TResourceInformationEntity> implements TResourceInformationService {

    @Autowired
    private TResourceInformationService tResourceInformationService;

//    @Autowired
//    private RestTemplate restTemplate;

    @Autowired
    private StudyCourseRemote studyCourseRemote;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        int size = params.size();
        IPage<TResourceInformationEntity> page=new Page<>();
        if(size==4){
            String keys="";
            String param="";
            Set<String> strings = params.keySet();
            for (String key : strings) {
                keys=key;
                param=params.get(keys).toString();
            }
            page = this.page(
                    new Query<TResourceInformationEntity>().getPage(params),
                    new QueryWrapper<TResourceInformationEntity>().eq(keys,param)
            );
            return new PageUtils(page);
        }
        page = this.page(
                new Query<TResourceInformationEntity>().getPage(params),
                new QueryWrapper<TResourceInformationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public R reviewResource(TResourceInformationEntity tCourseInformation) {
        String resourceAddress = tCourseInformation.getResourceAddress();
        if(StringUtils.isEmpty(resourceAddress)){
            return R.error("资源地址为空,不能预览");
        }
//        String url="http://localhost:88/api/sys/menu/reviewResource?resourceAddress="+resourceAddress;
//      restTemplate.getForObject(url,String.class);
        studyCourseRemote.alterResourceStataus(resourceAddress);
        return R.ok();
    }
}